package com.arcvideo.acsconnect.helper;

import android.content.Context;

import com.arcvideo.acsconnect.app.AcsConnectApplication;
import com.arcvideo.acsconnect.bean.MessageBean;
import com.arcvideo.acsconnect.rest.model.UserBean;
import com.arcvideo.arcrtcsdk.ArcRtcSDK;
import com.google.gson.Gson;

/**
 * @author shenmengchao
 * @version 1.0.0
 * @date 2018/9/6
 * @description
 */

public class MessageHelper {

    private static Context mApplicationContext;

    public static void setApplicationContext(Context appContext) {
        mApplicationContext = appContext;
    }

    public static int sendReplyMessage(String toAccount, String result, String sessionId) {
        if (null == mApplicationContext) {
            throw new RuntimeException("please setApplicationContext() before invoke this method");
        }
        UserBean userBean = AcsConnectApplication.getCurrentUserBean();
        //build message
        MessageBean messageBean = new MessageBean(
                sessionId, userBean.getId(), userBean.getName(), MessageBean.MSG_TYPE_REPLY);
        messageBean.setIconurl(userBean.getHeadPicUrl());
        messageBean.setResult(result);
        String msgJson = new Gson().toJson(messageBean);
        return ArcRtcSDK.create(mApplicationContext).sendMessage(toAccount, msgJson);
    }

    public static int sendInviteMessage(String toAccount, String sessionId) {
        UserBean userBean = AcsConnectApplication.getCurrentUserBean();
        //build message
        MessageBean messageBean = new MessageBean(
                sessionId, userBean.getId(), userBean.getName(), MessageBean.MSG_TYPE_INVITE);
        messageBean.setIconurl(userBean.getHeadPicUrl());
        String msgJson = new Gson().toJson(messageBean);
        return ArcRtcSDK.create(mApplicationContext).sendMessage(toAccount, msgJson);
    }

    public static int sendHangUpMessage(String toAccount, String sessionId) {
        UserBean userBean = AcsConnectApplication.getCurrentUserBean();
        //build message
        MessageBean messageBean = new MessageBean(
                sessionId, userBean.getId(), userBean.getName(), MessageBean.MSG_TYPE_HANG_UP);
        messageBean.setIconurl(userBean.getHeadPicUrl());
        String msgJson = new Gson().toJson(messageBean);
        return ArcRtcSDK.create(mApplicationContext).sendMessage(toAccount, msgJson);
    }
}
